﻿function onSettings(){	
	window.location.href='Settings.html';
}

function onDAU(e){	 
	var id=e.getAttribute("id")
	var type=1;
	if(id=="DAUYesterday"){
		type=1;
	}else if(id=="DAUMonth"){
		type=2;
	}else if(id=="DAUMonthAverage"){
		type=3;
	}else if(id=="DAUMAURate"){
		type=4;
	}
	console.log(type);
	window.location.href='DAU.html'+'?type='+type;
}

function onNewUser(e){
	var id=e.getAttribute("id");	
	if(id == 'yesterdayNewUsers'){
		window.location.href='NewUser.html'+'?type=1';
	}else{
		window.location.href='NewUser.html'+'?type=2';
	}
	
}

function onIncomeDaily(){
	//console.log("-----onIncomeDaily------");
	window.location.href='IncomeIndex.html'+'?type=1';
}
function onIncomeMonthly(){
	//console.log("-----onIncomeMonthly------");
	window.location.href='IncomeIndex.html'+'?type=2';
}


window.onload=  function(){
	requestDAUData();
	requestTotalNewUsers();
	requestIncomeIndex();
}

/***************************************************************
*运营侧数据请求开始
*
*****************************************************************/
function requestIncomeIndex(){
	requestDailyIncomeIndex();
	requestMonthlyIncomeIndex();
}

function requestMonthlyIncomeIndex(){
	var requestUrl=getIncomeMonthlyRequestUrl();
		$.ajax({
		type:"post",
		url:requestUrl,
		success:function(resultData){
			var flag = resultData.success;	
          	console.log("flag="+flag);		
			if(flag==1){
				var data = resultData.data;
				console.log("data.length="+data.length);			
                if(data.length>0){
					var dayData= data[0];
					var total=	Math.floor(dayData.total_fee/10000);
                    var baoyue=Math.floor(dayData.baoyue_fee/10000);					
					var dianbo=Math.floor(dayData.dianbo_fee/10000);						
					console.log("total="+total+",baoyue="+baoyue+",dianbo="+dianbo);	
				    document.getElementById("monthTotalValue").innerHTML=total;					
					document.getElementById("monthBaoyueValue").innerHTML=baoyue;
					document.getElementById("monthDianbaoValue").innerHTML=dianbo;
				}				
			}
		}
	});
}

function requestDailyIncomeIndex(){
	//console.log("-----requestDailyIncomeIndex---");
	var requestUrl=getIncomeDailyRequestUrl();
	//console.log("requestUrl="+requestUrl);
	$.ajax({
		type:"post",
		url:requestUrl,
		success:function(resultData){
			var flag = resultData.success;	
          	console.log("flag="+flag);		
			if(flag==1){
				var data = resultData.data;
				console.log("data.length="+data.length);			
                if(data.length>0){
					var dayData= data[0];
					var total=	Math.floor(dayData.total_fee/10000);
                    var baoyue=Math.floor(dayData.baoyue_fee/10000);					
					var dianbo=Math.floor(dayData.dianbo_fee/10000);						
					console.log("total="+total+",baoyue="+baoyue+",dianbo="+dianbo);	
				    document.getElementById("yesterdayTotalValue").innerHTML=total;					
					document.getElementById("yesterdayBaoyueValue").innerHTML=baoyue;
					document.getElementById("yesterdayDianboValue").innerHTML=dianbo;
				}				
			}
		}
	});
}

/***
*获取新增用户数
***/
function requestTotalNewUsers(){
	var requestUrl =getTotalNewUsersUrl();
	var processData=  function(resultData){
		var flag= resultData.success;		
		if(flag=='1'){
			var data=resultData.data[0];
			var dateNum=data.DAYNUM/10000;
			var monthNum=data.MONTHNUM/10000;			
			var dayNew=document.getElementById('newUsersDaily');
			dayNew.innerHTML=dateNum;
			var monthNew=document.getElementById('newUsersMonthly');
			monthNew.innerHTML=monthNum;
		}
	};
	sendRequest(requestUrl, processData);
}

function requestDAUData(){
	var requestUrl =getDAUUrlInMoniter();
	var processData= function(resultData){
		var flag= resultData.success;
		if(flag==1){
			//[{"DAYDAU":"0","RATE":0.03,"TOTAL_DAU":3541664,"AVG_DAU":1083.74}]}
			var data= resultData.data[0];
			var dayDAU= data.DAYDAU/10000;			
			var totalDAU=data.TOTAL_DAU/10000;
			var average=data.AVG_DAU/10000;
			var rate=data.RATE+"%";
			console.log(dayDAU);
			console.log(rate);
			console.log(totalDAU);
			console.log(average);
			var yDau= document.getElementById('yesterdayDAU');
			yDau.innerHTML=dayDAU;
			var mDau= document.getElementById('monthDAU');
			mDau.innerHTML=totalDAU;
			
			var aDau= document.getElementById('monthAverageDAU');
			aDau.innerHTML=average;			
			var dauRate= document.getElementById('DAURate');
			dauRate.innerHTML=rate;
		}
	}
	sendRequest(requestUrl, processData);
}
/********************运营侧数据结束*************************/

/*****************************************************************
*  
*
*****************************************************************/


